from typing import List, Tuple
from datetime import datetime, timedelta, date

from .Leave import Leave


class Staff:
    def __init__(self, 
            id: str,           # 人员ID
            name: str,         # 人员姓名
            cre_types: List,   # 人员资质列表
            ):
        self._id = id
        self._name = name
        self._cre_types = cre_types

    @property
    def id(self) -> str:
        return self._id

    @property
    def name(self) -> str:
        return self._name

    @property
    def cre_types(self) -> List:
        return self._cre_types


class WorkingStaff(Staff):
    def __init__(self,
            id: str,
            name: str,
            cre_types,
            work_start_time: datetime,          # 班制的出勤时间
            work_end_time: datetime,            # 班制的退勤时间
            avail_time: datetime,               # 员工执行完所有任务后，可供派遣的最早时间
            equip = None,                       # 设备绑定，默认无绑定
            ):                         

        Staff.__init__(self, id, name, cre_types)
        self._work_start_time = work_start_time
        self._work_end_time = work_end_time
        self._avail_time = avail_time

        self._had_lunch = False
        self._acc_work_time = timedelta(0)
        self._continuous_work_time = timedelta(0)


class SchedulingStaff(Staff):
    def __init__(self,
            id: str,
            name: str,
            cre_types,
            start_date: date,
            leave_list: List[Leave] = 0 
            ):
        Staff.__init__(self, id, name, cre_types)
        self._start_date = start_date
        self._leave_list = leave_list

        self._work_schedule: List = []

    @property
    def start_date(self) -> date:
        return self._start_date

    @property
    def work_schedule(self) -> List:
        return self._work_schedule

    def add_schedule(self, schedule_task):
        return self._work_schedule.append(schedule_task)

    @property
    def leave_list(self):
        return self._leave_list

    @property
    def schedule_summary(self):
        worklist = []       # 工作列表
        summary = {}        # 工作总结
        summary_str = ""    # 工作总结字符串
        for schedule_task in self.work_schedule:
            name = schedule_task.work_time.name

            worklist.append(name)

            if name not in summary.keys():
                summary[name] = 1
            else:
                summary[name] += 1

        for (key, value) in sorted(list(summary.items())):
            summary_str += f"{key}: {value}天， "

        return {"summary": summary, "summary_str": summary_str, "worklist": worklist}

    @property
    def work_schedule_cnt(self):
        return len(self._work_schedule)